#include <iostream>
#include <iomanip>
bool isPerfectNum(int n)
{
	int sum = 0;
	if (n == 1)
	{
		return false;
	}
	for (int i = 1; i < n; i++)
	{
		if (n % i == 0)
		{
			sum += i;
		}
	}
	if (sum == n)
	{
		return true;
	}
	return false;
}
int main()
{
        int count = 0, active = 0;
	for (int i = 1; i < 1000; i++)
	{
		if (isPerfectNum(i))
		{
			std::cout << std::setw(5) << i;
			count += 1;
			active = 1;
		}
		if (count % 5 == 0 && active)
		{
			std::cout << std::endl;
			active = 0;
		}
	}
}